package com.rising.face.ali.bishi.stringpipei;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: rising
 * @Description:
 * @Date: create in 2021/2/7 9:28
 */
public class StringPiPei {

    public boolean flag(String pattern, String sourceString) {
        //存放对应关系
        Map<String, String> duiying = new HashMap<String, String>();
        char[] chars = pattern.toCharArray();
        String[] strs = sourceString.split(" ");
        if (chars.length != strs.length) {
            return false;
        }
        for (int i = 0; i < chars.length; i++) {
            //对应关系不存在，则放进去
            if (duiying.get(strs[i]) == null) {
                duiying.put(strs[i], String.valueOf(chars[i]));
            }

            if (!duiying.get(strs[i]).equals(String.valueOf(chars[i]))) {
                return false;
            }

        }
        return true;
    }

    public static void main(String[] args) {
        String pattern = "aabb";
        String sourceString = "北京 北京 杭州 杭州";
        System.out.println(new StringPiPei().flag(pattern, sourceString));
    }

}
